
<script>
import _param from './param.vue'
//post方法获取参数

function axiosRequest(obj,uri,data,callBack) {
	obj.$ajax({
		url: _param.param.apiUrl+uri,
        method: 'post',
        response: 'json',
        data: data,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }).then(callBack).catch(function(err) {
        console.log('uri:'+uri+' got error :'+err);
    })
}
//axios.get('/user', {
//            params: {
//                ID: 12345
//            }
//        })
//        .then(function (response) {
//            console.log(response);
//        })
//        .catch(function (error) {
//            console.log(error);
//        });

//get方法获取字典
function axiosGet(obj,uri,callBack) {
    obj.$ajax.get( _param.param.apiUrl+uri).then(callBack).catch(function(err) {
        console.log('uri:'+uri+' got error :'+err);
    })
}
//带参数的请求
function axiosGetparam(obj,uri,param,callBack){
    obj.$ajax.get( _param.param.apiUrl+uri,param).then(callBack).catch(function(err) {
        console.log('uri:'+uri+' got error :'+err);
    })
}
function apiResult(obj,data){
    let returns = false
    if (data.result == 0){
        obj.$notify({
          title: '操作成功',
          message: '这是一条成功的提示消息',
          type: 'success'
        });
        returns = true
    }else if(data.result == -999){
        obj.$notify({
          title: '系统发生错误',
          message: '这是一条系统警告的提示消息',
          type: 'warning'
        });
    }else{
        obj.$notify.error({
          title: '操作失败',
          message: data.msg,
        });
    }
    return returns
}

function getUserId(){
  let userId =  localStorage.getItem('userId')
  if (!userId) {
    localStorage.clear()
    window.location.href="/"
  }
  return userId
}
function formValidate(obj,form,callBack){
  obj.$refs[form].validate(callBack)
}
//递归进行权限读取
function getLimit(allLimit,id){
    for(var i= 0;i<allLimit.length;i++ ){
        var obj = allLimit[i]
        if(obj.sysPermission.id==id){
            status=obj.sysPermission.flag
            break
        }else{
            if(obj.subSysPermission){
               var parentNode=obj.subSysPermission
                getLimit(parentNode,id)
            }else{
                continue
            }
        }
    }
    return{
        status:status
    }
}
	export default{
		axiosRequest,
		apiResult,
        getUserId,
        formValidate,
        axiosGet,
        axiosGetparam,
        getLimit
	}
</script>
